package com.zzyy.study.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageClient;
import org.springframework.ai.openai.OpenAiImageOptions;
import org.springframework.ai.openai.api.OpenAiImageApi;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2024-05-18 16:06
 */
@RestController
public class ImageOpenAIController
{
    @Resource
    private OpenAiImageClient openAiImageClient;


    @GetMapping(value = "/ai/imagev1")
    public Object imageV1(@RequestParam(value = "msg",defaultValue = "苹果") String msg)
    {
        ImageResponse imageResponse = openAiImageClient.call(new ImagePrompt(msg));
        System.out.println("------imageResponse: "+imageResponse);

        return imageResponse.getResult().getOutput();
    }

    @GetMapping(value = "/ai/imagev2")
    public Object imageV2(@RequestParam(value = "msg",defaultValue = "苹果") String msg)
    {
        ImageResponse imageResponse = openAiImageClient.call(new ImagePrompt(msg,
                        OpenAiImageOptions.builder()
                                .withQuality("hd") //高清图
                                .withN(1)       //生成1张
                                .withHeight(1024)   //高
                                .withWidth(1024)    //宽
                                .build()));
        System.out.println("------imageResponse: "+imageResponse);
        return imageResponse.getResult().getOutput();
    }
}
